package com.cn.longdistancebusstation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cn.longdistancebusstation.R;
import com.cn.longdistancebusstation.model.OrderInfo;

import java.util.List;

/**
 * Created by Administrator on 2018/1/16.
 */

public class ComplishAdapter extends BaseAdapter{
    private Context ctx;
    private List<OrderInfo> list;
    public ComplishAdapter(Context ctx,List<OrderInfo> list){
        this.ctx=ctx;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView= LayoutInflater.from(ctx).inflate(R.layout.view_order_accomplish,null);
            holder.order_number=(TextView)convertView.findViewById(R.id.order_number);
            holder.order_time = (TextView)convertView.findViewById(R.id.order_time);
            holder.order_from_station_name=(TextView)convertView.findViewById(R.id.origin_name);
            holder.order_arrive_station_name=(TextView)convertView.findViewById(R.id.terminal_name);
            holder.bus_number=(TextView)convertView.findViewById(R.id.motorcoachnumber);
            holder.ride_time=(TextView)convertView.findViewById(R.id.departure_time);
            holder.ticket_amount=(TextView)convertView.findViewById(R.id.ticket_number);
            holder.pick_up_ticket=(TextView)convertView.findViewById(R.id.pick_up_ticket);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder)convertView.getTag();
        }
        OrderInfo info=list.get(position);
        holder.order_number.setText(info.getOrderNo());
        holder.order_time.setText(info.getOrderDate());
        holder.order_from_station_name.setText(info.getFromStationName());
        holder.order_arrive_station_name.setText(info.getToStationName());
        holder.bus_number.setText(info.getBusNo());
        //发车时间只显示"日期"
        String strSendDate = info.getSendDate();
        if(info.getIsFlow() == 1){
            //流水车
            holder.ride_time.setText(strSendDate.split(" ")[0] + "流水车");
        }
        else{
            holder.ride_time.setText(strSendDate);
        }
        holder.ticket_amount.setText(info.getTickets()+"");
        if("已取票".equals(info.getCustomAddress())){
            holder.pick_up_ticket.setVisibility(View.VISIBLE);
        }else{
            holder.pick_up_ticket.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }
    class ViewHolder{
        TextView order_number;              //订单号
        TextView order_time;                //订单时间
        TextView order_from_station_name;   //始发站
        TextView order_arrive_station_name; //目的地
        TextView bus_number;                //车次
        TextView ride_time;                 //发车时间
        TextView ticket_amount;             //票数
        TextView pick_up_ticket;            //是否取票
    }
}
